//
//  FamilyRoomService.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/23.
//  Copyright © 2020 tym. All rights reserved.
//

#import "FamilyRoomService.h"
#import "YYModel.h"
@implementation FamilyRoomService


/*创建修改家庭房间*/
-(void)getFamilyroomcreatefamilyroomFamilyId:(NSInteger)famileId
                                  roomName:(NSString*)roomName roomDesc:(nullable NSString* )roomDesc image:(nullable NSString*)image
                                       rooID:(NSInteger)rooid completion:(void(^)(LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"familyId":@(famileId),
                          @"roomName":roomName,@"roomDesc":roomDesc?roomDesc:@"",
                          @"image":image?image:@"",
                          @"id":rooid>0? @(rooid):@""
    };
    [self POST:urlFamilyroomcreatefamilyroom parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*删除家庭房间*/
-(void)getDeletefamilyroomFamilyId:(NSInteger)famileId
                                   completion:(void(^)(LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"id":@(famileId)
    };
    [self POST:urlFamilyroomdeletefamilyroom parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*添加修改家庭房间用户*/
-(void)getCreatefamilyroomuserFamilyId:(NSInteger)famileId
                          familyRoomId:(NSInteger)familyRoomId
                            userIdList:(NSArray*)userIdList
                                   completion:(void(^)(LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"familyId":@(famileId),
                          @"familyRoomId":@(familyRoomId),
                          @"userIdList":[userIdList componentsJoinedByString:@","]
    };
    [self POST:urlFamilyroomusercreatefamilyroomuser parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

-(void)getUpdatefamilyroomuserRoomUserID:(NSInteger)userid
status:(NSInteger)status
                              completion:(void(^)(LMJBaseResponse *response))completion{
    NSDictionary *dic = @{@"id":@(userid),
                          @"staus":@(status)
    };
    [self POST:urlFamilyroomuserupdatefamilyroomuser parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

-(void)getFindfamilyroomfamilyId:(NSInteger)familyId
                              completion:(void(^)(LMJBaseResponse *response,NSArray *roosArry))completion{
    NSDictionary *dic = @{@"familyId":@(familyId)
    };
    [self POST:urlFamilyroomfindfamilyroom parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[NSArray yy_modelArrayWithClass:[RoomModel class] json:response.responseObject[@"data"]]);
    }];
}

-(void)getFindfamilyroomusersFamilyId:(NSInteger)familyId
                         familyRoomId:(NSInteger)familyRoomId
                              completion:(void(^)(LMJBaseResponse *response,NSArray *roosArry))completion{
    NSDictionary *dic = @{@"familyId":@(familyId),
                          @"familyRoomId":@(familyRoomId)
    };
    [self POST:urlFamilyroomuserfindfamilyroomusers parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[NSArray yy_modelArrayWithClass:[UserModel class] json:response.responseObject[@"data"]]);
    }];
}

//获取用户详情
-(void)getRoomuserdetailUserId:(NSInteger)userId
                              completion:(void(^)(LMJBaseResponse *response,UserModel *userModel))completion{
    NSDictionary *dic = @{@"userId":@(userId)
    };
    [self POST:urlFamilyroomfindfamilyroom parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[UserModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

//获取家庭所有房间及所有设备
-(void)getFindfamilyroomequipment:(NSInteger)familyId
                           completion:(void(^)(LMJBaseResponse *response,NSArray <RoomModel*>*roosArry))completion{
    NSDictionary *dic = @{@"familyId":@(familyId)
    };
    [self POST:urlFamilyinfofindfamilyroomequipment parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response, [NSArray yy_modelArrayWithClass:[RoomModel class] json:response.responseObject[@"data"]]);
    }];
    
}
@end
